package com.yydm.serviceedu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yydm.serviceedu.entity.Founder;
import com.yydm.serviceedu.mapper.FounderMapper;
import com.yydm.serviceedu.service.IFounderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author yydm
 * @since 2022-07-05
 */
@Service
public class FounderServiceImpl extends ServiceImpl<FounderMapper, Founder> implements IFounderService {

    @Override
    public Map<String, Object> getFounderFront(Page<Founder> page) {

        QueryWrapper<Founder> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        baseMapper.selectPage(page, wrapper);

//        数组list集合
        List<Founder> records = page.getRecords();
        long current = page.getCurrent();
        long pages = page.getPages();
        long size = page.getSize();
//        总记录数
        long total = page.getTotal();
        boolean hasNext = page.hasNext();  //下一页
        boolean hasPrevious = page.hasPrevious(); //上一页

        HashMap<String, Object> map = new HashMap<>();
        map.put("items", records);
        map.put("current", current);
        map.put("pages", pages);
        map.put("size", size);
        map.put("total", total);
        map.put("hasNext", hasNext);
        map.put("hasPrevious", hasPrevious);

        return map;
    }
}
